home *** CD-ROM | disk | FTP | other *** search
- # Source Generated with Decompyle++
- # File: in.pyo (Python 2.5)
-
- import os
- import sys
- import warnings
- from ZSI import _get_idstr
- from ZSI.wstools.logging import getLogger as _GetLogger
- from ZSI.wstools import WSDLTools
- from ZSI.wstools.WSDLTools import SoapAddressBinding, SoapBodyBinding, SoapBinding, MimeContentBinding, HttpUrlEncodedBinding
- from ZSI.wstools.XMLSchema import SchemaReader, ElementDeclaration, SchemaError
- from ZSI.typeinterpreter import BaseTypeInterpreter
- from ZSI.generate import WsdlGeneratorError, Wsdl2PythonError
- from containers import *
- from ZSI.generate import utility
- from ZSI.generate.utility import NamespaceAliasDict as NAD
- from ZSI.generate.utility import GetModuleBaseNameFromWSDL
-
- class WriteServiceModule:
- client_module_suffix = '_client'
- messages_module_suffix = '_messages'
- types_module_suffix = '_types'
- logger = _GetLogger('WriteServiceModule')
-
- def __init__(self, wsdl, addressing = False, notification = False, do_extended = False, extPyClasses = None, configParser = None):
- self._wsdl = wsdl
- self._addressing = addressing
- self._notification = notification
- self._configParser = configParser
- self.usedNamespaces = None
- self.services = []
- self.client_module_path = None
- self.types_module_name = None
- self.types_module_path = None
- self.messages_module_path = None
- self.do_extended = do_extended
- self.extPyClasses = extPyClasses
-
-
- def getClientModuleName(self):
- name = GetModuleBaseNameFromWSDL(self._wsdl)
- if not name:
- raise WsdlGeneratorError, 'could not determine a service name'
-
- if self.client_module_suffix is None:
- return name
-
- return '%s%s' % (name, self.client_module_suffix)
-
-
- def setTypesModuleName(self, name):
- self.types_module_name = name
-
-
- def getTypesModuleName(self):
- if self.types_module_name is not None:
- return self.types_module_name
-
- name = GetModuleBaseNameFromWSDL(self._wsdl)
- if not name:
- raise WsdlGeneratorError, 'could not determine a service name'
-
- if self.types_module_suffix is None:
- return name
-
- return '%s%s' % (name, self.types_module_suffix)
-
-
- def setClientModulePath(self, path):
- self.client_module_path = path
-
-
- def getTypesModulePath(self):
- return self.types_module_path
-
-
- def setTypesModulePath(self, path):
- self.types_module_path = path
-
-
- def gatherNamespaces(self):
- if self.usedNamespaces is not None:
- return None
-
- self.logger.debug('gatherNamespaces')
- self.usedNamespaces = { }
- for schema in self._wsdl.types.values():
- tns = schema.getTargetNamespace()
- self.logger.debug('Register schema(%s) -- TNS(%s)' % (_get_idstr(schema), tns))
- if self.usedNamespaces.has_key(tns) is False:
- self.usedNamespaces[tns] = []
-
- self.usedNamespaces[tns].append(schema)
- NAD.add(tns)
-
- for k, v in SchemaReader.namespaceToSchema.items():
- self.logger.debug('Register schema(%s) -- TNS(%s)' % (_get_idstr(v), k))
- if self.usedNamespaces.has_key(k) is False:
- self.usedNamespaces[k] = []
-
- self.usedNamespaces[k].append(v)
- NAD.add(k)
-
-
-
- def writeClient(self, fd, sdClass = None, **kw):
- if not sdClass:
- pass
- sdClass = ServiceDescription
- print >>fd, '#' * 50
- print >>fd, '# file: %s.py' % self.getClientModuleName()
- print >>fd, '# '
- print >>fd, '# client stubs generated by "%s"' % self.__class__
- print >>fd, '# %s' % ' '.join(sys.argv)
- print >>fd, '# '
- print >>fd, '#' * 50
- self.services = []
- for service in self._wsdl.services:
- sd = sdClass(self._addressing, do_extended = self.do_extended, wsdl = self._wsdl)
- if len(self._wsdl.types) > 0:
- sd.setTypesModuleName(self.getTypesModuleName(), self.getTypesModulePath())
-
- self.gatherNamespaces()
- sd.fromWsdl(service, **kw)
- sd.write(fd)
- self.services.append(sd)
-
-
-
- def writeTypes(self, fd):
- print >>fd, '#' * 50
- print >>fd, '# file: %s.py' % self.getTypesModuleName()
- print >>fd, '#'
- print >>fd, '# schema types generated by "%s"' % self.__class__
- print >>fd, '# %s' % ' '.join(sys.argv)
- print >>fd, '#'
- print >>fd, '#' * 50
- print >>fd, TypesHeaderContainer()
- self.gatherNamespaces()
- for l in self.usedNamespaces.values():
- sd = SchemaDescription(do_extended = self.do_extended, extPyClasses = self.extPyClasses)
- for schema in l:
- sd.fromSchema(schema)
-
- sd.write(fd)
-
-
-
-
- class ServiceDescription:
- separate_messages = False
- logger = _GetLogger('ServiceDescription')
-
- def __init__(self, addressing = False, do_extended = False, wsdl = None):
- self.typesModuleName = None
- self.messagesModuleName = None
- self.wsAddressing = addressing
- self.imports = ServiceHeaderContainer()
- self.messagesImports = ServiceHeaderContainer()
- self.locator = ServiceLocatorContainer()
- self.bindings = []
- self.messages = []
- self.do_extended = do_extended
- self._wsdl = wsdl
-
-
- def setTypesModuleName(self, name, modulePath = None):
- self.typesModuleName = '%s' % name
- if modulePath is not None:
- self.typesModuleName = '%s.%s' % (modulePath, name)
-
-
-
- def fromWsdl(self, service, **kw):
- self.imports.setTypesModuleName(self.typesModuleName)
- self.imports.appendImport(kw.get('imports', []))
- self.locator.setUp(service)
-
- try:
- bindings = map((lambda p: p.binding), service.ports)
- except:
- warnings.warn('not all ports have binding declared,')
- bindings = ()
-
- for port in service.ports:
- if port.binding not in bindings:
- continue
-
- while port.binding in bindings:
- bindings.remove(port.binding)
- desc = BindingDescription(useWSA = self.wsAddressing, do_extended = self.do_extended, wsdl = self._wsdl)
-
- try:
- desc.setUp(port.getBinding())
- except Wsdl2PythonError:
- ex = None
- self.logger.warning('Skipping port(%s)' % port.name)
- if len(ex.args):
- self.logger.warning(ex.args[0])
- continue
- continue
-
- desc.setReaderClass(kw.get('readerclass'))
- desc.setWriterClass(kw.get('writerclass'))
- for soc in desc.operations:
- if soc.hasInput() is True:
- mw = MessageWriter(do_extended = self.do_extended)
- mw.setUp(soc, port, input = True)
- self.messages.append(mw)
- if soc.hasOutput() is True:
- mw = MessageWriter(do_extended = self.do_extended)
- mw.setUp(soc, port, input = False)
- self.messages.append(mw)
-
- soc.hasOutput() is True
-
- self.bindings.append(desc)
-
-
-
- def write(self, fd, msg_fd = None):
- print >>fd, self.imports
- print >>fd, self.locator
- for m in self.bindings:
- print >>fd, m
-
- for m in self.messages:
- print >>fd, m
-
-
-
-
- class MessageWriter:
- logger = _GetLogger('MessageWriter')
-
- def __init__(self, do_extended = False):
- self.content = None
- self.do_extended = do_extended
-
-
- def __str__(self):
- if not self.content:
- raise Wsdl2PythonError, 'Must call setUp.'
-
- return self.content.getvalue()
-
-
- def setUp(self, soc, port, input = False):
- rpc = soc.isRPC()
- literal = soc.isLiteral(input)
- kw = { }
- klass = None
- if rpc and literal:
- klass = ServiceRPCLiteralMessageContainer
- elif not rpc and literal:
- kw['do_extended'] = self.do_extended
- klass = ServiceDocumentLiteralMessageContainer
- elif rpc and not literal:
- klass = ServiceRPCEncodedMessageContainer
- else:
- raise WsdlGeneratorError, 'doc/enc not supported.'
- self.content = klass(**kw)
- self.content.setUp(port, soc, input)
-
-
-
- class SchemaDescription:
- logger = _GetLogger('SchemaDescription')
-
- def __init__(self, do_extended = False, extPyClasses = None):
- self.classHead = NamespaceClassHeaderContainer()
- self.classFoot = NamespaceClassFooterContainer()
- self.items = []
- self._SchemaDescription__types = []
- self._SchemaDescription__elements = []
- self.targetNamespace = None
- self.do_extended = do_extended
- self.extPyClasses = extPyClasses
-
-
- def fromSchema(self, schema):
- ns = schema.getTargetNamespace()
- if self.targetNamespace is None:
- self.targetNamespace = ns
-
- self.classHead.ns = self.classFoot.ns = ns
- for t in schema.types:
- if t.getAttributeName() not in self._SchemaDescription__types:
- continue
- _[1][t]
-
- for e in schema.elements:
- if e.getAttributeName() not in self._SchemaDescription__elements:
- continue
- _[2][e]
-
-
-
- def getTypes(self):
- return self._SchemaDescription__types
-
-
- def getElements(self):
- return self._SchemaDescription__elements
-
-
- def write(self, fd):
- print >>fd, self.classHead
- for t in self.items:
- print >>fd, t
-
- print >>fd, self.classFoot
-
-
-
- class SchemaItemWriter:
- logger = _GetLogger('SchemaItemWriter')
-
- def __init__(self, do_extended = False, extPyClasses = None):
- self.content = None
- self.do_extended = do_extended
- self.extPyClasses = extPyClasses
-
-
- def __str__(self):
- return str(self.content)
-
-
- def fromSchemaItem(self, item):
- raise NotImplementedError, ''
-
-
-
- class ElementWriter(SchemaItemWriter):
- logger = _GetLogger('ElementWriter')
-
- def fromSchemaItem(self, item):
- if item.isElement() is False or item.isLocal() is True:
- raise TypeError, 'expecting global element declaration: %s' % item.getItemTrace()
-
- local = False
- qName = item.getAttribute('type')
- if not qName:
- etp = item.content
- local = True
- else:
- etp = item.getTypeDefinition('type')
- if etp is None:
- if local is True:
- self.content = ElementLocalComplexTypeContainer(do_extended = self.do_extended)
- else:
- self.content = ElementSimpleTypeContainer()
- elif etp.isLocal() is False:
- self.content = ElementGlobalDefContainer()
- elif etp.isSimple() is True:
- self.content = ElementLocalSimpleTypeContainer()
- elif etp.isComplex():
- self.content = ElementLocalComplexTypeContainer(do_extended = self.do_extended)
- else:
- raise Wsdl2PythonError, 'Unknown element declaration: %s' % item.getItemTrace()
- self.logger.debug('ElementWriter setUp container "%r", Schema Item "%s"' % (self.content, item.getItemTrace()))
- self.content.setUp(item)
-
-
-
- class TypeWriter(SchemaItemWriter):
- logger = _GetLogger('TypeWriter')
-
- def fromSchemaItem(self, item):
- if item.isDefinition() is False or item.isLocal() is True:
- raise TypeError, 'expecting global type definition not: %s' % item.getItemTrace()
-
- self.content = None
- if item.isSimple():
- if item.content.isRestriction():
- self.content = RestrictionContainer()
- elif item.content.isUnion():
- self.content = UnionContainer()
- elif item.content.isList():
- self.content = ListContainer()
- else:
- raise Wsdl2PythonError, 'unknown simple type definition: %s' % item.getItemTrace()
- self.content.setUp(item)
- return None
-
- if item.isComplex():
- kw = { }
- if item.content is None or item.content.isModelGroup():
- self.content = ComplexTypeContainer(do_extended = self.do_extended, extPyClasses = self.extPyClasses)
- kw['empty'] = item.content is None
- elif item.content.isSimple():
- self.content = ComplexTypeSimpleContentContainer()
- elif item.content.isComplex():
- self.content = ComplexTypeComplexContentContainer(do_extended = self.do_extended)
- else:
- raise Wsdl2PythonError, 'unknown complex type definition: %s' % item.getItemTrace()
- self.logger.debug('TypeWriter setUp container "%r", Schema Item "%s"' % (self.content, item.getItemTrace()))
-
- try:
- self.content.setUp(item, **kw)
- except Exception:
- ex = None
- args = [
- 'Failure in setUp: %s' % item.getItemTrace()]
- args += ex.args
- ex.args = tuple(args)
- raise
-
- return None
-
- raise TypeError, 'expecting SimpleType or ComplexType: %s' % item.getItemTrace()
-
-
-